package com.cvoms.modules.app.service.impl;

import com.cvoms.modules.app.dao.OrderDao;
import com.cvoms.modules.app.entity.OrderEntity;
import com.cvoms.modules.app.service.OrderService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cvoms.common.utils.PageUtils;
import com.cvoms.common.utils.Query;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;


@Service("orderService")
public class OrderServiceImpl extends ServiceImpl<OrderDao, OrderEntity> implements OrderService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<OrderEntity> wrapper = new QueryWrapper<OrderEntity>();
        if(StringUtils.hasText((String)params.get("orderNo"))){
            wrapper.eq("order_no",params.get("orderNo")).or();
        }
        if(StringUtils.hasText((String)params.get("phone"))){
            wrapper.eq("phone",params.get("phone")).or();
        }
        if(StringUtils.hasText((String)params.get("phone"))){
            wrapper.eq("payee",params.get("payee")).or();
        }

        List<String>  orderNoList = (ArrayList)params.get("orderNoList");
        if(!CollectionUtils.isEmpty(orderNoList)){
            wrapper.in("order_no",orderNoList);
        }

        IPage<OrderEntity> page = this.page(
                new Query<OrderEntity>().getPage(params),wrapper);

        return new PageUtils(page);
    }

}